package com.sjzxywlkj.cplife.alipay.result;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import com.alipay.api.AlipayApiException;
import com.alipay.api.domain.CplifeRoomDetail;
import com.alipay.api.domain.CplifeRoomInfoResp;
import com.alipay.api.response.AlipayEcoCplifeRoominfoDeleteResponse;
import com.alipay.api.response.AlipayEcoCplifeRoominfoQueryResponse;
import com.alipay.api.response.AlipayEcoCplifeRoominfoUploadResponse;
import com.sjzxywlkj.cplife.alipay.conn.RoominfoConn;
import com.sjzxywlkj.cplife.alipay.request.entity.RoominfoDelete;
import com.sjzxywlkj.cplife.alipay.request.entity.RoominfoQuery;
import com.sjzxywlkj.cplife.alipay.request.entity.RoominfoUpload;
import com.sjzxywlkj.cplife.alipay.response.entity.*;


/**
 * 房屋操作返回结果
 */
public class RoominfoAlipay {

    //上传物业小区内部房屋信息
    public static Map<String, Object> upload(RoominfoUpload roominfoUpload, String app_auth_token) throws AlipayApiException {
        AlipayEcoCplifeRoominfoUploadResponse response = RoominfoConn.upload(roominfoUpload, app_auth_token);


        Map<String, Object> result = new HashMap<String, Object>();
        PublicParameters parameters = new PublicParameters(response.getCode(), response.getMsg(), response.getSubCode(), response.getSubMsg(), null);
        List<Room_info_set> room_info_sets = new ArrayList<Room_info_set>();
        if (response.getRoomInfoSet() != null) {
            for (CplifeRoomInfoResp cpResp : response.getRoomInfoSet()) {
                Room_info_set rSet = new Room_info_set(cpResp.getOutRoomId(), cpResp.getRoomId());
                room_info_sets.add(rSet);
            }
        }

        RoominfoUploadResult roominfoUploadResult = new RoominfoUploadResult(response.getCommunityId(), room_info_sets);
        result.put("parameters", parameters);
        result.put("roominfoUploadResult", roominfoUploadResult);
        return result;

    }

    //删除物业小区房屋信息
    public static Map<String, Object> delete(RoominfoDelete roominfoDelete, String app_auth_token) throws AlipayApiException {
        AlipayEcoCplifeRoominfoDeleteResponse response = RoominfoConn.delete(roominfoDelete, app_auth_token);

        Map<String, Object> result = new HashMap<String, Object>();
        PublicParameters parameters = new PublicParameters(response.getCode(), response.getMsg(), response.getSubCode(), response.getSubMsg(), null);
        RoominfoDeleteResult roominfoDeleteResult = new RoominfoDeleteResult();
        result.put("parameters", parameters);
        result.put("roominfoDeleteResult", roominfoDeleteResult);
        return result;

    }

    //查询小区房屋信息列表
    public static Map<String, Object> query(RoominfoQuery roominfoQuery, String app_auth_token) throws AlipayApiException {
        AlipayEcoCplifeRoominfoQueryResponse response = RoominfoConn.query(roominfoQuery, app_auth_token);

        Map<String, Object> result = new HashMap<String, Object>();

        PublicParameters parameters = new PublicParameters(response.getCode(), response.getMsg(), response.getSubCode(), response.getSubMsg(), null);
        List<Room_info> room_infos = new ArrayList<Room_info>();
        if (response.getRoomInfo() != null) {
            for (CplifeRoomDetail cDetail : response.getRoomInfo()) {
                Room_info rInfo = new Room_info(cDetail.getOutRoomId(), cDetail.getRoomId(), cDetail.getGroup(), cDetail.getBuilding(), cDetail.getUnit(), cDetail.getRoom(), cDetail.getAddress());
                room_infos.add(rInfo);
            }
        }

        RoominfoQueryResult roominfoQueryResult = new RoominfoQueryResult(new Long(response.getTotalRoomNumber()).intValue(), room_infos);
        result.put("parameters", parameters);
        result.put("roominfoQueryResult", roominfoQueryResult);
        return result;

    }
}
